Class MockConnection

Summary

Fully Qualified Name: CodeIgniter\Test\Mock\MockConnection
Extends: BaseConnection

Description

Methods

Name Description Defined By
__construct() Saves our connection settings. BaseConnection
__get() Accessor for properties if they exist. BaseConnection
__isset() Checker for properties existence. BaseConnection
addTableAlias() Add a table alias to our list. BaseConnection
affectedRows() Returns the total number of rows affected by this query. MockConnection
callFunction() This function enables you to call PHP database functions that are not natively included in CodeIgniter, in a platform independent manner. BaseConnection
close() Close the database connection. BaseConnection
connect() Connect to the database. MockConnection
disableForeignKeyChecks() Disables foreign key checks temporarily. BaseConnection
enableForeignKeyChecks() Enables foreign key checks temporarily. BaseConnection
error() Returns the last error code and message. MockConnection
escape() "Smart" Escape String BaseConnection
escapeIdentifiers() Escape the SQL Identifiers BaseConnection
escapeLikeString() Escape LIKE String BaseConnection
escapeString() Escape String BaseConnection
fieldExists() Determine if a particular field exists BaseConnection
getConnectDuration() Returns the number of seconds with microseconds that it took to connect to the database. BaseConnection
getConnectStart() Returns the time we started to connect to this database in seconds with microseconds. BaseConnection
getConnection() Returns the actual connection object. If both a 'read' and 'write' connection has been specified, you can pass either term in to get that connection. If you pass either alias in and only a single connection is present, it must return the sole connection. BaseConnection
getDatabase() Returns the name of the current database being used. BaseConnection
getError() Returns the last error encountered by this connection. BaseConnection
getFieldData() Returns an object with field data BaseConnection
getFieldNames() Fetch Field Names BaseConnection
getForeignKeyData() Returns an object with foreign key data BaseConnection
getIndexData() Returns an object with key data BaseConnection
getLastQuery() Returns the last query's statement object. BaseConnection
getPlatform() The name of the platform in use (MySQLi, mssql, etc) BaseConnection
getPrefix() Returns the database prefix. BaseConnection
getVersion() Returns a string containing the version of the database being used. MockConnection
initialize() Initializes the database connection/settings. BaseConnection
insertID() Insert ID MockConnection
listTables() Returns an array of table names BaseConnection
persistentConnect() Create a persistent database connection. BaseConnection
prefixTable() DB Prefix BaseConnection
prepare() Creates a prepared statement with the database that can then be used to execute multiple statements against. Within the closure, you would build the query in any normal way, though the Query Builder is the expected manner. BaseConnection
pretend() Allows the engine to be set into a mode where queries are not actually executed, but they are still generated, timed, etc. BaseConnection
protectIdentifiers() Protect Identifiers BaseConnection
query() Orchestrates a query against the database. Queries must use Database\Statement objects to store the query and build it. MockConnection
reconnect() Keep or establish the connection if no queries have been sent for a length of time exceeding the server's idle timeout. MockConnection
resetDataCache() Empties our data cache. Especially helpful during testing. BaseConnection
setAliasedTables() Sets the Table Aliases to use. These are typically collected during use of the Builder, and set here so queries are built correctly. BaseConnection
setDatabase() Select a specific database table to use. MockConnection
setPrefix() Set DB Prefix BaseConnection
shouldReturn() MockConnection
showLastQuery() Returns a string representation of the last query's statement object. BaseConnection
simpleQuery() Performs a basic query against the database. No binding or caching is performed, nor are transactions handled. Simply takes a raw query string and returns the database-specific result id. BaseConnection
table() Returns an instance of the query builder for this connection. BaseConnection
tableExists() Determine if a particular table exists BaseConnection
transBegin() Begin Transaction BaseConnection
transCommit() Commit Transaction BaseConnection
transComplete() Complete Transaction BaseConnection
transOff() Disable Transactions BaseConnection
transRollback() Rollback Transaction BaseConnection
transStart() Start Transaction BaseConnection
transStatus() Lets you retrieve the transaction flag to determine if it has failed BaseConnection
transStrict() Enable/disable Transaction Strict Mode BaseConnection

Method Details

__construct()

Saves our connection settings.

Parameter Name Type Description
$params array

Returns:

__get()

Accessor for properties if they exist.

Parameter Name Type Description
$key string

Returns: mixed

__isset()

Checker for properties existence.

Parameter Name Type Description
$key string

Returns: bool

addTableAlias()

Add a table alias to our list.

Parameter Name Type Description
$table string

Returns: $this

affectedRows()

Returns the total number of rows affected by this query.

Returns: int

callFunction()

This function enables you to call PHP database functions that are not natively included in CodeIgniter, in a platform independent manner.

Parameter Name Type Description
$functionName string
...$params array
$params

Returns: bool

close()

Close the database connection.

Returns: void

connect()

Connect to the database.

Parameter Name Type Description
$persistent bool

Returns: mixed

disableForeignKeyChecks()

Disables foreign key checks temporarily.

Returns:

enableForeignKeyChecks()

Enables foreign key checks temporarily.

Returns:

error()

Returns the last error code and message.

Must return an array with keys 'code' and 'message':

return ['code' => null, 'message' => null);

Returns: array

escape()

"Smart" Escape String

Escapes data based on type. Sets boolean and null types

Parameter Name Type Description
$str mixed

Returns: mixed

escapeIdentifiers()

Escape the SQL Identifiers

This function escapes column and table names

Parameter Name Type Description
$item mixed

Returns: mixed

escapeLikeString()

Escape LIKE String

Calls the individual driver for platform specific escaping for LIKE conditions

Parameter Name Type Description
$ string|string[]
$str

Returns: string|string[]

escapeString()

Escape String

Parameter Name Type Description
$str string|string[] Input
$like bool Whether

Returns: string|string[]

fieldExists()

Determine if a particular field exists

Parameter Name Type Description
$fieldName string
$tableName string

Returns: bool

getConnectDuration()

Returns the number of seconds with microseconds that it took to connect to the database.

Used by the Debug Toolbar's timeline.

Parameter Name Type Description
$decimals int

Returns: string

getConnectStart()

Returns the time we started to connect to this database in seconds with microseconds.

Used by the Debug Toolbar's timeline.

Returns: float|null

getConnection()

Returns the actual connection object. If both a 'read' and 'write' connection has been specified, you can pass either term in to get that connection. If you pass either alias in and only a single connection is present, it must return the sole connection.

Parameter Name Type Description
$alias string|null

Returns: mixed

getDatabase()

Returns the name of the current database being used.

Returns: string

getError()

Returns the last error encountered by this connection.

Returns: mixed

getFieldData()

Returns an object with field data

Parameter Name Type Description
$table string the

Returns: array|bool

getFieldNames()

Fetch Field Names

Parameter Name Type Description
$table string Table

Returns: array|bool

getForeignKeyData()

Returns an object with foreign key data

Parameter Name Type Description
$table string the

Returns: array|bool

getIndexData()

Returns an object with key data

Parameter Name Type Description
$table string the

Returns: array|bool

getLastQuery()

Returns the last query's statement object.

Returns: mixed

getPlatform()

The name of the platform in use (MySQLi, mssql, etc)

Returns: string

getPrefix()

Returns the database prefix.

Returns: string

getVersion()

Returns a string containing the version of the database being used.

Returns: string

initialize()

Initializes the database connection/settings.

Returns: mixed|void

insertID()

Insert ID

Returns: int

listTables()

Returns an array of table names

Parameter Name Type Description
$constrainByPrefix bool =

Returns: bool|array

persistentConnect()

Create a persistent database connection.

Returns: mixed

prefixTable()

DB Prefix

Prepends a database prefix if one exists in configuration

Parameter Name Type Description
$table string the

Returns: string

prepare()

Creates a prepared statement with the database that can then be used to execute multiple statements against. Within the closure, you would build the query in any normal way, though the Query Builder is the expected manner.

Example: $stmt = $db->prepare(function($db)

   {
     return $db->table('users')
           ->where('id', 1)
             ->get();
   })
Parameter Name Type Description
$func \Closure
$options array Passed

Returns: \BasePreparedQuery|null

pretend()

Allows the engine to be set into a mode where queries are not actually executed, but they are still generated, timed, etc.

This is primarily used by the prepared query functionality.

Parameter Name Type Description
$pretend bool

Returns: $this

protectIdentifiers()

Protect Identifiers

This function is used extensively by the Query Builder class, and by a couple functions in this class. It takes a column or table name (optionally with an alias) and inserts the table prefix onto it. Some logic is necessary in order to deal with column names that include the path. Consider a query like this:

SELECT hostname.database.table.column AS c FROM hostname.database.table

Or a query with aliasing:

SELECT m.member_id, m.member_name FROM members AS m

Since the column name can include up to four segments (host, DB, table, column) or also have an alias prefix, we need to do a bit of work to figure this out and insert the table prefix (if it exists) in the proper position, and escape only the correct identifiers.

Parameter Name Type Description
$item string|array
$prefixSingle bool
$protectIdentifiers bool
$fieldExists bool

Returns: string|array

query()

Orchestrates a query against the database. Queries must use Database\Statement objects to store the query and build it.

This method works with the cache.

Should automatically handle different connections for read/write queries if needed.

Parameter Name Type Description
$sql string
...$binds mixed
$setEscapeFlags bool
$queryClass string
$binds

Returns: \CodeIgniter\Database\BaseResult|\CodeIgniter\Database\Query|bool

reconnect()

Keep or establish the connection if no queries have been sent for a length of time exceeding the server's idle timeout.

Returns: bool

resetDataCache()

Empties our data cache. Especially helpful during testing.

Returns: $this

setAliasedTables()

Sets the Table Aliases to use. These are typically collected during use of the Builder, and set here so queries are built correctly.

Parameter Name Type Description
$aliases array

Returns: $this

setDatabase()

Select a specific database table to use.

Parameter Name Type Description
$databaseName string

Returns: mixed

setPrefix()

Set DB Prefix

Set's the DB Prefix to something new without needing to reconnect

Parameter Name Type Description
$prefix string The

Returns: string

shouldReturn()

Parameter Name Type Description
$method
$return

Returns: void

showLastQuery()

Returns a string representation of the last query's statement object.

Returns: string

simpleQuery()

Performs a basic query against the database. No binding or caching is performed, nor are transactions handled. Simply takes a raw query string and returns the database-specific result id.

Parameter Name Type Description
$sql string

Returns: mixed

table()

Returns an instance of the query builder for this connection.

Parameter Name Type Description
$tableName string|array

Returns: \BaseBuilder

tableExists()

Determine if a particular table exists

Parameter Name Type Description
$tableName string

Returns: bool

transBegin()

Begin Transaction

Parameter Name Type Description
$test_mode bool

Returns: bool

transCommit()

Commit Transaction

Returns: bool

transComplete()

Complete Transaction

Returns: bool

transOff()

Disable Transactions

This permits transactions to be disabled at run-time.

Returns: void

transRollback()

Rollback Transaction

Returns: bool

transStart()

Start Transaction

Parameter Name Type Description
$test_mode bool =

Returns: bool

transStatus()

Lets you retrieve the transaction flag to determine if it has failed

Returns: bool

transStrict()

Enable/disable Transaction Strict Mode

When strict mode is enabled, if you are running multiple groups of transactions, if one group fails all subsequent groups will be rolled back.

If strict mode is disabled, each group is treated autonomously, meaning a failure of one group will not affect any others

Parameter Name Type Description
$mode bool =

Returns: $this

Top